package lx;

import java.util.Arrays;
import java.util.Comparator;

public class demo1 {
    public static void main(String[] args) {
        Girlfriend g1 = new Girlfriend("zhangsan", 18, 90);
        Girlfriend g2 = new Girlfriend("lisi", 19, 100);
        Girlfriend g3 = new Girlfriend("wangwu", 20, 110);
        //定义数组存储对象
        Girlfriend[] arr = {g1, g2, g3};
        // Arrays.sort(arr, new Comparator<Girlfriend>() {
               /* public int compare(Girlfriend o1, Girlfriend o2) {
                //按照年龄的大小进行比较,年龄一样,按照身高比较,身高一样按照姓名的字母比较
                double tmp = o1.getAge() - o2.getAge();
                tmp = tmp == 0 ? o1.getHeight() - o2.getHeight() : tmp;
                tmp = tmp == 0 ? o1.getName().compareTo(o2.getName()) : tmp;
                if (tmp < 0) {
                    return -1;
                } else if (tmp > 0) {
                    return 1;
                } else
                    return 0;
            }
        });*/
        //lambda表达式
        //()->{}
        //():对应抽象方法的形参
        //{}:方法体
        Arrays.sort(arr, (o1, o2) -> {
            //按照年龄的大小进行比较,年龄一样,按照身高比较,身高一样按照姓名的字母比较
                double tmp = o1.getAge() - o2.getAge();
            tmp = tmp == 0 ? o1.getHeight() - o2.getHeight() : tmp;
            tmp = tmp == 0 ? o1.getName().compareTo(o2.getName()) : tmp;
            if (tmp < 0) {
                return -1;
            } else if (tmp > 0) {
                return 1;
            } else
                return 0;

        });
        System.out.println(Arrays.toString(arr));
    }
}
